﻿using Common.Attributes;
using IEntities;
using IRepository;
using IServices;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Services
{
    public abstract class BaseService<TEntity>:IBaseService<TEntity>where TEntity:class,IEntity
    {
        private IBaseRepository<TEntity> _repository;

        public BaseService(IBaseRepository<TEntity> repository)
        {
            _repository = repository;
        }

        public virtual object[] Test() => _repository.Test();
        public virtual int Count() => _repository.Count();
        public virtual int Count(Expression<Func<TEntity, bool>> whereExpression) => _repository.Count(whereExpression);
        public virtual Task<int> CountAsync() => _repository.CountAsync();
        public virtual Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.CountAsync(whereExpression);
        public virtual bool Delete(TEntity entity) => _repository.Delete(entity);
        public virtual Task DeleteAsync(TEntity entity) => _repository.DeleteAsync(entity);
        public virtual bool DeleteByID(object id) => _repository.DeleteByID(id);
        public virtual Task DeleteByIDAsync(object id) => _repository.DeleteByIDAsync(id);
        public virtual bool Deletes(dynamic[] ids) => _repository.Deletes(ids);
        public virtual Task DeletesAsync(dynamic[] ids) => _repository.DeletesAsync(ids);
        public virtual TEntity Find(Expression<Func<TEntity, bool>> whereExpression) => _repository.Find(whereExpression);
        public virtual Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.FindAsync(whereExpression);
        public virtual TEntity FindByID(object id) => _repository.FindByID(id);
        public virtual Task<TEntity> FindByIDAsync(object id) => _repository.FindByIDAsync(id);
        public virtual TEntity FirstOrDefault(object id) => _repository.FirstOrDefault(id);
        public virtual TEntity FirstOrDefault(Expression<Func<TEntity, bool>> whereExpression) => _repository.FirstOrDefault(whereExpression);
        public virtual Task<TEntity> FirstOrDefaultAsync(object id) => _repository.FirstOrDefaultAsync(id);
        public virtual Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.FirstOrDefaultAsync(whereExpression);
        public virtual TEntity Get(object id) => _repository.Get(id);
        public virtual TEntity Get(Expression<Func<TEntity, bool>> whereExpression) => _repository.Get(whereExpression);
        public virtual List<TEntity> GetAllList() => _repository.GetAllList();
        public virtual List<TEntity> GetAllList(Expression<Func<TEntity, bool>> whereExpression) => _repository.GetAllList(whereExpression);
        public virtual Task<List<TEntity>> GetAllListAsync() => _repository.GetAllListAsync();
        public virtual Task<List<TEntity>> GetAllListAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.GetAllListAsync(whereExpression);
        public virtual Task<TEntity> GetAsync(object id) => _repository.GetAsync(id);
        public virtual Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.GetAsync(whereExpression);
        public virtual TEntity Insert(TEntity entity) => _repository.Insert(entity);
        public virtual object InsertAndGetID(TEntity entity) => _repository.InsertAndGetID(entity);
        public virtual Task<object> InsertAndGetIDAsync(TEntity entity) => _repository.InsertAndGetIDAsync(entity);
        public virtual Task<TEntity> InsertAsync(TEntity entity) => _repository.InsertAsync(entity);
        public virtual List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression) => _repository.Query(whereExpression);
        public virtual Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression) => _repository.QueryAsync(whereExpression);
        public virtual List<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 10, int pageCount = 10) => _repository.QueryPage(whereExpression);
        public virtual Task<List<TEntity>> QueryPageAsync(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 10, int pageCount = 10) => _repository.QueryPageAsync(whereExpression);
        public virtual TEntity Update(TEntity entity) => _repository.Update(entity);
        public virtual object UpdateAndGetID(TEntity entity) => _repository.UpdateAndGetID(entity);
        public virtual Task<object> UpdateAndGetIDAsync(TEntity entity) => _repository.UpdateAndGetIDAsync(entity);
        public virtual Task<TEntity> UpdateAsync(TEntity entity) => _repository.UpdateAsync(entity);
        public virtual List<TEntity> Updates(List<TEntity> entities) => _repository.Updates(entities);
        public virtual Task<List<TEntity>> UpdatesAsync(List<TEntity> entities) => _repository.UpdatesAsync(entities);
    }
}
